app.controller("userUpd",function($scope,$uibModal,$rootScope,del,$state,get,pos,post,$stateParams,Md5){
	$scope.search=function(){
		 get.list('user/findOne',{uId:$stateParams.id}).then(function(e) {
		  	$scope.name=e.uAccount
		  	$scope.pwd=e.uPassword
		  	$scope.telephone=e.uPhone
		  	$scope.state=e.uState==1?true:false
		  	$scope.list=e
		  }); 
	}
	/**
	 * 提交
	 */
	$scope.change=function(val){
		for(i=0;i<$scope.list.roles.length;i++){
			if ($scope.list.roles[i].checked==true) {
			     $scope.isshows=false
			     break 
			}else{
				 $scope.isshows=true
			}
		}
	}
	$scope.submitForm=function(){
		$scope.arr=''
		angular.forEach($scope.list.roles,function(o){
			if (o.checked==true) {
			     $scope.arr+=o.id+","
			} 
			
		})
		
		
		
		var param={
			userRoles:$scope.arr,
			uAccount:$scope.name,
			uPhone:$scope.telephone||'',
			uState:$scope.state==true?1:0,
			uPassword:null,
			uId:$stateParams.id
		}
		if($scope.ispwd){
			param.uPassword=Md5.hex_md5($scope.pwd)
		}else{
			param.uPassword=$scope.pwd
		}
		
			post.list("user/update",param).then(function(e){
				$rootScope.open(e);
				$state.go("home.user",null,{
					     		reload:true
					     	})
			})
		
		
		
		
	}
	$scope.search()
	$scope.password=function(){
		if( $scope.pwd!=null){
			$scope.ispwd=true
		}
		
	}
})
